﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DotNetNuke.Modules.SkinObjectsEx
{
    internal static class EnumConversion
    {
        internal static Enum ConvertFromEnum(Type enumType, string rawValue, Enum defaultValue)
        {
            if (rawValue != null)
            {
                Enum result = defaultValue;
                try
                {
                    object enumVal = Enum.Parse(enumType, rawValue);
                    result = (Enum)Convert.ChangeType(enumVal, enumType);
                }
                catch (Exception ex)
                {
                    //ignore because we can't implement Enum.TryParse until .NET 4
                }
                return result;
            }
            else
                return defaultValue;
            
        }
    }
}
